package com.black.web.app.store;

import com.black.app.domain.req.store.add.AppStoreAddressesAddReq;
import com.black.app.domain.req.store.edit.AppStoreAddressesEditReq;
import com.black.app.domain.req.store.query.AppStoreAddressesQueryReq;
import com.black.app.domain.resp.store.AppStoreAddressesResp;
import com.black.app.service.store.AppStoreAddressesService;
import com.black.common.core.controller.BaseController;
import com.black.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "app-收件人地址相关Api")
@RestController
@RequestMapping("/app/store/addresses")
public class StoreAddressesController extends BaseController {

    @Autowired
    private AppStoreAddressesService storeAddressesService;

    /**
     * 分页查询
     *
     * @param req
     * @return
     */

    @ApiOperation(value = "分页查询地址详情")
    @GetMapping("/list")
    public R<PageInfo<AppStoreAddressesResp>> paginationQuery(AppStoreAddressesQueryReq req) {
        PageInfo<AppStoreAddressesResp> page = this.storeAddressesService.paginationQuery(req);
        return R.ok(page);
    }

    @ApiOperation(value = "新增地址")
    @PostMapping
    public R add(@RequestBody @Valid AppStoreAddressesAddReq req) {
        boolean result = this.storeAddressesService.add(req);
        return super.isSuccess(result);
    }

    @ApiOperation(value = "修改地址")
    @PutMapping
    public R edit(@RequestBody @Valid AppStoreAddressesEditReq req) {
        boolean result = this.storeAddressesService.edit(req);
        return super.isSuccess(result);
    }

    @ApiOperation(value = "根据addressId查询地址")
    @GetMapping(value = "/{addressId}")
    public R<AppStoreAddressesResp> findByAddressId(@PathVariable(value = "addressId") Long addressId) {
        return R.ok(this.storeAddressesService.findByAddressId(addressId));
    }

    @ApiOperation(value = "删除地址")
    @DeleteMapping(value = "/{ids}")
    public R delete(@PathVariable(value = "ids") Long[] ids) {
        boolean result = this.storeAddressesService.deleteById(ids);
        return super.isSuccess(result);
    }


}
